#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QRgb>
#include <QFileDialog>
#include <QMessageBox>
#include <QGraphicsScene>
#include <QMouseEvent>
#include <QDebug>
#include <QColorDialog>
#include <QPainter>
#include <qmath.h>

#include <QLabel>
#include "tools.h"
#include <vector>

namespace Ui {
class MainWindow;
}
struct MarkPoint{
    int index;
    int label;
    bool operator==(const MarkPoint& other)
    {
        if ((index==other.index)&&(label==other.label))
        {
            return true;
        }
        return false;
    }
};
struct MarkColor{
    int label;
    QRgb color;
    bool operator==(const MarkColor& other)
    {
        if (label==other.label)
        {
            return true;
        }
        return false;
    }
};

class MainWindow : public QMainWindow , public Tools
{
    Q_OBJECT
    
public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();
    
private slots:
    void on_pb_Load_clicked();
    void on_pb_selectFile_clicked();
    void on_spinBox_valueChanged(int arg1);
    void on_pb_Save_clicked();
    void on_spinBox_Value_valueChanged(int arg1);
    void on_pb_Test_clicked();

    void on_pb_Clear_clicked();

private:
    Ui::MainWindow *ui;
    QImage *originImage;
    QImage *showImage;
    void keyPressEvent(QKeyEvent *key);
    bool eventFilter(QObject *o, QEvent *e);
    bool checkMousePos(int x,int y);
    void mouseMoveEvent(QMouseEvent *event);
    void mousePressEvent(QMouseEvent *event);
    void mouseReleaseEvent(QMouseEvent *event);
    void setLabelColor(QLabel *,QRgb);
    bool checkn(int n);
    QRgb getMarkColor(int label);
    void updateView();
    void addMarkPoint(QPoint startPoint,QPoint endPoint,int label);
    QVector<QPoint> getPoints(QPoint startPoint,QPoint endPoint);
    void fixPos();
    QPoint getMousePos(int x , int y);
    QPoint getOriginPos(int x,int y);
    QVector<MarkPoint> markPoints;
    QVector<MarkColor> markColors;
    int n;
    int view_width, view_height; // size of the view window
    long int origin_width,origin_height; // size of origin pic
    long int resize_width,resize_height; // size of resize pic
    long int row_center,col_center;  //center pos of region show
    int move_start_x,move_start_y,move_end_x,move_end_y;
    int move_dx,move_dy;
    QRgb defaultLabelColor;
    QPoint mark_start_point;
    bool loaded ;
    bool markstyle;
};
#endif // MAINWINDOW_H
